import data
import pyglet
import pygletutil
from pyglet.gl import *
from timer import *
from pyglet.window import key

import math

from level import *
from robot import *
from component import *

class RobotGame(object):
	def __init__(self, keys):
		super(RobotGame, self).__init__()
		self.keys=keys
		self.level = Level()
		self.playerObject = Robot(self.keys,x=300.0,y=300.0)
		thrusterBottomRight = Thruster(angle=225.0,distance=40.0, image='thruster1')
		thrusterBottomLeft = Thruster(angle=135.0,distance=40.0, image='thruster2')
		thrusterTopRight = Thruster(angle=315.0,distance=40.0, rotation=180)
		thrusterTopLeft = Thruster(angle=45.0,distance=40.0, rotation=180)
		thrusterTopMiddle = Thruster(angle=0.0,distance=40.0,rotation=180, image='thruster4')
		self.playerObject.addComponent(thrusterBottomLeft, key.RIGHT)
		self.playerObject.addComponent(thrusterBottomRight, key.LEFT)
		#self.playerObject.addComponent(thrusterTopLeft, key.LEFT)
		#self.playerObject.addComponent(thrusterTopRight, key.RIGHT)
		self.playerObject.addComponent(thrusterTopMiddle,key.DOWN)
		self.playerObject.bindKey(thrusterBottomLeft, key.UP)
		self.playerObject.bindKey(thrusterBottomRight, key.UP)
		self.playerObject.bindKey(thrusterTopMiddle,key.LEFT)
		self.playerObject.bindKey(thrusterTopMiddle,key.RIGHT)
		#self.playerObject.bindKey(thrusterTopLeft, key.DOWN)
		#self.playerObject.bindKey(thrusterTopRight, key.DOWN)
		self.spaceObjects = []
		self.spaceObjects.append(self.playerObject)
		
		self.fps_display = pyglet.clock.ClockDisplay()
		
	def draw(self):
		self.playerObject.update()
		glClearColor(0,0,0,1.0)
		for obj in self.spaceObjects:
			obj.draw()
		self.fps_display.draw()
	
	def handleKeys(self,symbol,modifier):
		pass